import java.util.*;

public class Gesture implements java.lang.Comparable<Gesture>
{
    private String name;
    private ArrayList<PointR> rawPoints;
    private ArrayList<PointR> points;

    public Gesture()
    {
        this.name = "";
        this.rawPoints = null;
        this.points = null;
    }

    public Gesture(String name, ArrayList<PointR> points)
    {
        this.name = name;
        this.rawPoints = points;

        this.points = Utils.resample(points, GeometricRecognizer.NUM_RESAMPLE_POINTS);
        double radians = Utils.angleInRadians(Utils.centroid(this.points),
                (PointR) this.points.get(0), false);
        this.points = Utils.rotateByRadians(this.points, -radians);
        this.points = Utils.scaleTo(this.points, GeometricRecognizer.RESAMPLE_SCALE);
        this.points = Utils.translateCentroidTo(this.points, GeometricRecognizer.RESAMPLE_ORIGIN);
    }

    public int duration()
    {
        if (this.rawPoints.size() >= 2)
        {
            PointR p0 = (PointR) this.rawPoints.get(0);
            PointR pn = (PointR) this.rawPoints.get(rawPoints.size() - 1);
            return (pn.t - p0.t);
        }
        else
        {
            return 0;
        }
    }

    public void setPoints(ArrayList<PointR> p)
    {
        this.points = p;
    }

    public void setRawPoints(ArrayList<PointR> p)
    {
        this.rawPoints = p;
    }

    public void setName(String s)
    {
        this.name = s;
    }

    public ArrayList<PointR> getPoints()
    {
        return this.points;
    }

    public String getName()
    {
        return this.name;
    }

    public ArrayList<PointR> getRawPoints()
    {
        return this.rawPoints;
    }

    public int compareTo(Gesture o)
    {
        if (o instanceof Gesture)
        {
            return this.name.compareTo(((Gesture) o).name);
        }
        throw new java.lang.IllegalArgumentException("o is not a Gesture");
    }

    public static String parseName(String filename)
    {
        int start = filename.lastIndexOf('\\');
        int end = filename.lastIndexOf('.');
        return filename.substring(start + 1, end - start - 1);
    }
}
